/* 
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <QUrl>

#include "components/board.h"
#include "components/chan.h"
#include "components/post.h"
#include "components/thread.h"
#include "postdocument.h"
#include "chanmanager.h"
#include "log.h"
#include "postitemview.h"

PostDocument::PostDocument(PostItemView* parent) : QTextDocument(parent), m_view(parent)
{
}

PostDocument::~PostDocument()
{
}

QVariant PostDocument::loadResource(int type, const QUrl& name)
{
	if(type == QTextDocument::ImageResource)
	{
		int imageIndex = name.path().mid(1).toUInt();
		if(imageIndex < 0 || imageIndex >= m_images.size())
			return QVariant(QImage());
		return m_images.at(imageIndex);
	}
	return QVariant();
}

void PostDocument::setImage(int index, const QImage& image)
{
	if(index >= m_images.size())
		m_images.resize(index + 1);
	m_images[index] = image;
}

